package cn.le.controller;

import cn.le.beans.dto.ExcelHomeSearchDto;
import cn.le.beans.vo.PageVo;
import cn.le.beans.vo.ResponseVO;
import cn.le.service.ExcelHomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description
 * @Author le
 * @Date 2020/2/16 12:38
 * @Version 0.1
 **/
@RestController
@RequestMapping(value = "/excel")
@Api(value = "Excel房源信息")
public class ExcelHomeController {

    @Autowired
    private ExcelHomeService homeExcelService;

    @ApiOperation(value = "替换总房源")
    @PostMapping(value = "/replace")
    public ResponseVO replace(@RequestParam(value = "file") MultipartFile file) throws Exception {
        homeExcelService.replace(file);
        return ResponseVO.success();
    }

    @ApiOperation(value = "新增房源")
    @PostMapping(value = "/newAdd")
    public ResponseVO newAdd(@RequestParam(value = "file") MultipartFile file) throws Exception {
        homeExcelService.newAdd(file);
        return ResponseVO.success();
    }

    @ApiOperation(value = "Excel房源信息检索")
    @PostMapping(value = "/page")
    public ResponseVO search(@RequestBody ExcelHomeSearchDto dto) throws Exception {
        return ResponseVO.success("完成", PageVo.restPage(homeExcelService.search(dto)));
    }
}
